package com.dm.cloud.controller;

import com.dm.cloud.api.dto.Orders;
import com.dm.cloud.common.R;
import com.dm.cloud.api.service.IOrderService;
import io.seata.core.context.RootContext;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Log4j2
@RestController
@RequestMapping("order")
public class OrderController {

    @Autowired
    private IOrderService orderService;

    @GetMapping("/search/{orderNo}")
    public R<Orders> search(@PathVariable("orderNo") String orderNo){
        log.info("get order detail,orderNo is :{}",orderNo);
        return orderService.selectByCode(orderNo);
    }

    @PostMapping("/create")
    public R<Orders> create(@RequestBody Orders orders) throws Exception {
        log.info("create order:{}", orders);
        log.info("XID:{}", RootContext.getXID());
        return orderService.orderCreate(orders);
    }


}
